package posti.test.domain;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Book {
	public Object thisField = this;
	public Object nullField = null;
	private int id = -1;
	private List<Author> authors;
	private String title;
	private String isbn;
	private Review review;
	private int version = -1;

	protected Book() {
		this.authors = new ArrayList<Author>();
	}

	public Book(String title) {
		this();
		this.title = title;
	}
	
	public void addAuthor(Author author) {
		this.authors.add(author);
	}
	
	public Iterator iterateAuthors() {
		return authors.iterator();
	}
	
	public void setReview(Review review) {
		this.review = review;
	}
	
	public Review getReview() {
		return this.review;
	}
	
	public void isbn(String isbn) {
		this.isbn = isbn;
	}
	
	public String isbn() {
		return this.isbn;
	}
	
	public Author author(String firstName) {
		for (Author author : this.authors) {
			if (author.getFirstName().equals(firstName))
				return author;
		}
		return null;
	}
	
	public Object thisMethod() {
		return this;
	}
	public Object getThis() {
		return this;
	}
	
	public Object nullMethod() {
		return null;
	}
	public Object getNull() {
		return null;
	}

	public int getId() {
		return this.id;
	}

	public int getVersion() {
		return this.version;
	}

	@Override
	public int hashCode() {
		return isbn.hashCode();
	}

	@Override
	public boolean equals(Object arg0) {
		return arg0 instanceof Book? isbn.equals(((Book) arg0).isbn()) : false;
	}
}
